package moon.excel.template;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TplGroupDescribe {
	public static final int DYNAMIC_EXTEND_TYPE_SHANG = 0;
	public static final int DYNAMIC_EXTEND_TYPE_XIA = 1;
	public static final int DYNAMIC_EXTEND_TYPE_ZUO = 2;
	public static final int DYNAMIC_EXTEND_TYPE_YOU = 3;

	/** 值 */
	private String key;
	/** 模板cell */
	private Map<String, TplCellWraper> cells = new HashMap<String, TplCellWraper>();
	/** 填充值 */
	private List<Object> fillVals = new ArrayList<Object>();
	private int tplFirstRow;
	private int tplLastRow;
	private int tplFirstColumn;
	private int tplLastColumn;

	private int firstRow;
	private int lastRow;
	private int firstColumn;
	private int lastColumn;
	private int dynamicExtendType = DYNAMIC_EXTEND_TYPE_XIA;

	public TplGroupDescribe(String key, TplCellWraper tplCell) {
		super();
		this.key = key;
		cells.put(key, tplCell);
	}

	public void addKey(String key, TplCellWraper tplCell) {
		cells.put(key, tplCell);
	}

	public TplGroupDescribe(String key) {
		super();
		this.key = key;
	}

	public void initRange(int firstRow, int lastRow, int firstColumn, int lastColumn) {
		this.tplFirstRow = firstRow;
		this.tplLastRow = lastRow;
		this.tplFirstColumn = firstColumn;
		this.tplLastColumn = lastColumn;
		this.firstRow = firstRow;
		this.lastRow = lastRow;
		this.firstColumn = firstColumn;
		this.lastColumn = lastColumn;
	}

	public void setNewRange(int firstRow, int lastRow, int firstColumn, int lastColumn) {
		this.firstRow = firstRow;
		this.lastRow = lastRow;
		this.firstColumn = firstColumn;
		this.lastColumn = lastColumn;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public List<Object> getFillVals() {
		return fillVals;
	}

	public void setFillVals(List<Object> fillVals) {
		this.fillVals = fillVals;
	}

	public boolean isSingle() {
		return fillVals.size() == 1;
	}

	public TplCellWraper getCell(String key) {
		return cells.get(key);
	}

	public Collection<TplCellWraper> getAllCell() {
		return cells.values();
	}

	public int getDynamicExtendType() {
		return dynamicExtendType;
	}

	public void setDynamicExtendType(int dynamicExtendType) {
		this.dynamicExtendType = dynamicExtendType;
	}

	
	
	public int getTplFirstRow() {
		return tplFirstRow;
	}

	public void setTplFirstRow(int tplFirstRow) {
		this.tplFirstRow = tplFirstRow;
	}

	public int getTplLastRow() {
		return tplLastRow;
	}

	public void setTplLastRow(int tplLastRow) {
		this.tplLastRow = tplLastRow;
	}

	public int getTplFirstColumn() {
		return tplFirstColumn;
	}

	public void setTplFirstColumn(int tplFirstColumn) {
		this.tplFirstColumn = tplFirstColumn;
	}

	public int getTplLastColumn() {
		return tplLastColumn;
	}

	public void setTplLastColumn(int tplLastColumn) {
		this.tplLastColumn = tplLastColumn;
	}

	public int getFirstRow() {
		return firstRow;
	}

	public void setFirstRow(int firstRow) {
		this.firstRow = firstRow;
	}

	public int getLastRow() {
		return lastRow;
	}

	public void setLastRow(int lastRow) {
		this.lastRow = lastRow;
	}

	public int getFirstColumn() {
		return firstColumn;
	}

	public void setFirstColumn(int firstColumn) {
		this.firstColumn = firstColumn;
	}

	public int getLastColumn() {
		return lastColumn;
	}

	public void setLastColumn(int lastColumn) {
		this.lastColumn = lastColumn;
	}

	public Map<String, TplCellWraper> getCells() {
		return cells;
	}

	public void setCells(Map<String, TplCellWraper> cells) {
		this.cells = cells;
	}

	public boolean isChange() {
		return tplFirstRow != firstRow || tplLastRow != lastRow || tplFirstColumn != firstColumn || tplLastColumn != lastColumn;
	}

	public boolean isMerge() {
		return firstRow != lastRow || firstColumn != lastColumn;
	}

	@Override
	public String toString() {
		return "TplGroupDescribe [key=" + key + ", cells=" + cells + ", fillVals=" + Arrays.toString(fillVals.toArray()) + ", tplFirstRow=" + tplFirstRow + ", tplLastRow=" + tplLastRow + ", tplFirstColumn=" + tplFirstColumn + ", tplLastColumn=" + tplLastColumn + ", firstRow=" + firstRow + ", lastRow=" + lastRow + ", firstColumn=" + firstColumn + ", lastColumn=" + lastColumn + ", dynamicExtendType=" + dynamicExtendType + "]";
	}

}
